package com.kocla.mz.htmltextview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import org.sufficientlysecure.htmltextview.HtmlTextView;
import org.sufficientlysecure.htmltextview.ImageClickListener;

import java.util.List;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("$$\\sum_{i=1}^n a_i=0$$,");

        stringBuilder.append("$$f(x)=x^{x^x}$$");
        stringBuilder.append("$$f(x_1,x_x,\\ldots,x_n) = x_1^2 + x_2^2 + \\cdots + x_n^2 $$");
        stringBuilder.append("$$\\left. \\frac{du}{dx} \\right|_{x=0}.$$");
        stringBuilder.append("f(n) = \\begin{cases} \\frac{n}{2}, & \\text{if } n\\text{ is even} \\\\ 3n+1, & \\text{if } n\\text{ is odd} \\end{cases}");

        stringBuilder.append("$$\\mbox{对任意的$x>0$}, \\mbox{有 }f(x)>0. $$");
        stringBuilder.append("$$\\sqrt[n]{x_r_r_r} $$");
        stringBuilder.append("$$ \\frac{x+2}{x} \\sqrt{x} $$");
        stringBuilder.append("$$ \\[f(x,y,z) = 3y^2 z \\left( 3 + \\frac{7x+5}{1 + y^2} \\right).\\] $$");

        stringBuilder.append("$$ P(x|c)=\\frac{P(c|x)\\cdot P(x)}{P(x)} $$");
        stringBuilder.append("$$ \\Large x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a} $$");
        stringBuilder.append("$$ \\sum_{i=1}^n i = \\frac{n(n+1)}2 $$");
        stringBuilder.append("$$ f(x)=\\int_{-\\infty}^x e^{-t^2}dt $$ 这道公式我也不知道怎么做");

        stringBuilder.append("$$ \\cos 2\\theta  = \\cos^2 \\theta - \\sin^2 \\theta = 2 \\cos^2 \\theta - 1. $$");

        stringBuilder.append("$$ \\displaystyle= \\frac{k(k+1)}{2}+k+1 $$");
        stringBuilder.append("$$ \\frac{x}{2}-3=0 $$");
        stringBuilder.append("$$ x=\\frac{3}{2} $$");
        stringBuilder.append("$$ \\[ \\sum_{k=1}^n k^2 = \\frac{1}{2} n (n+1).\\] $$");

        String html =
            /*"$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$\n\n" +
            "\radg\n" +
            "$\\[\\sum_{k=1}^n k^2 = \\frac{1}{2}n(n+1).\\]$\n\n" +
            "\n" +
            "$e^{\\pi i} + 1 = 0$\n\n" +*/
                "<table border=\"1\">\n" +
                        "<tr>\n" +
                        "<td>row 1, cell 1</td>\n" +
                        "<td>row 1, cell 2</td>\n" +
                        "</tr>\n" +
                        "<tr>\n" +
                        "<td>row 2, cell 1</td>\n" +
                        "<td>row 2, cell 2</td>\n" +
                        "</tr>\n" +
                        "</table>" +
                        //
                        "\n" +
                        "<div id=\"gwdShare_con_1\" style=\"top:-10px;\">\n" +
                        "<div id=\"gwdshare\" class=\"gwdshare_t gwds_tools_24 get-codes-gwdshare\">\n" +
                        "<a class=\"gwds_weixin\" style=\"margin:-1px 3px 0px 3px; background:url(/govweb/xhtml/2016gov/images/public/share.png) no-repeat; background-position:2px -33px !important\" title=\"微信\" href=\"#\">&nbsp;</a>\n" +
                        "<a class=\"gwds_tsina\" style=\"margin:-1px 3px 0px 3px; background:url(/govweb/xhtml/2016gov/images/public/share.png) no-repeat; background-position:2px 5px !important\" title=\"新浪微博\" href=\"#\">&nbsp;</a>\n" +
                        "<span class=\"gwds_more\" style=\"width:32px;height:32px; margin:10px 0px 0px 6px; background:url(/govweb/xhtml/2016gov/images/public/icon_17.jpg) no-repeat 0 0;overflow:hidden;_display:block;_height:32px;\">&nbsp;</span>\n" +
                        "</div>\n" +
                        "</div>\n" +
                        "</div>\n" +
                        "\t\t\t\t</div>\n" +
                        "\t\t\t</div>\n" +
                        "      </div>\n" +
                        "      <div class=\"pages_content\" id=\"UCAP-CONTENT\">\n" +
                        "        <p style=\"font-family: 宋体; font-size: 12pt;\" align=\"center\"><img src=\"http://www.gov.cn/premier/2017-07/25/5213316/images/7a07baeb087947b492557fbefe50227b.jpg\" border=\"0\"><br>\n" +
                        "</p>\n" +
                        "<p style=\"font-family: 宋体; font-size: 12pt;\" align=\"center\"><img src=\"http://www.gov.cn/premier/2017-07/25/5213316/images/1beaa83d093d4878bf3705233223270b.jpg\" border=\"0\"><br>\n" +
                        "</p>\n" +
                        "<p style=\"text-indent: 2em; font-family: 宋体; font-size: 12pt;\"><span style=\"font-weight: bold;\">“互联网+”面向全球，老外在中国发现新机遇</span></p>\n" +
                        "<p style=\"text-indent: 2em; font-family: 宋体; font-size: 12pt;\">“中国在大力推动‘互联网+’，这本身就是面向全球的。”6月28日，李克强总理同出席2017年夏季达沃斯论坛的国际工商企业界代表对话交流时的这一表态，被视为向外商释放的“强信号”。</p>\n" +
                        "</p>\n" +
                        "<p style=\"text-indent: 2em; font-family: 宋体; font-size: 12pt;\"><span style=\"font-weight: bold;\">美国两年而中国只需半年，硬件创业首选中国</span></p>\n" +
                        "<p style=\"text-indent: 2em; font-family: 宋体; font-size: 12pt;\">正如李克强总理所言：“我们的创业创新是开放的，要总结经验，吸引更多国家的企业带着资金来、带着技术来、带着人才来，在合作中实现共赢。” &nbsp;（<span style=\"font-size: 12pt; text-indent: 2em;\">新京报特约记者 穆伊）</span></p>\n" +
                        "      </div>\n" +
                        "<div class=\"editor\"><span><a href=\"http://www.gov.cn/fuwu/jiucuo.htm\" target=\"_blank\">【我要纠错】</a> </span>责任编辑：刘杨 </div>\n" +
                        "<div id=\"pageBreak\"></div>\n" +
                        "<script type=\"text/javascript\">manuscriptPage_N()</script>\n" +
                        "      <div id=\"div_div\">\n" +
                        "        <div id=\"qr_container\" style=\"margin:auto; position:relative;\">扫一扫在手机打开当前页</div>\n" +
                        "</div>\n" +
                        //
                        "<div class=\"rights\">\n" +
                        "<div class=\"rights-title\">版权声明</div>\n" +
                        "<div class=\"instructions\">\n" +
                        "本文仅代表作者观点，不代表百度立场。<br/>本文系作者授权百度百家发表，未经许可，不得转载。</div>"
                        + "<p><span style=\"font-size:16px;font-family:arial,&#39;宋体&#39;,simsun\">若" +
                        "<img style=\"vertical-align:middle\" src='http://static.kocla.com/kocla/2017-03-20/8a20ae9c4082b5e6014084e8b46d0031/import_exam/23140817727216746/image024.gif' width=\"85\" height=\"39\" />，则" +
                        "<img style=\"vertical-align:middle\" id=\"对象 81\" src='http://static.kocla.com/kocla/2017-03-20/8a20ae9c4082b5e6014084e8b46d0031/import_exam/23140817727216746/image025.gif' width=\"51\" height=\"39\" />＝<span style=\"text-decoration:underline\">　　　</span><span style=\"text-decoration:underline\">　　　</span>．</span></p>";

        String latex = "One would typeset this in LaTeX by typing In non-relativistic wave mechanics, the wave function\n" +
                "$\\psi(\\mathbf{r},t)$ of a particle satisfies the\n" +
                "\\emph{Schr\\\"{o}dinger Wave Equation}\n" +
                "\\[ i\\hbar\\frac{\\partial \\psi}{\\partial t}\n" +
                "= \\frac{-\\hbar^2}{2m} \\left(\n" +
                "\\frac{\\partial^2}{\\partial x^2}\n" +
                "+ \\frac{\\partial^2}{\\partial y^2}\n" +
                "+ \\frac{\\partial^2}{\\partial z^2}\n" +
                "\\right) \\psi + V \\psi.\\]\n" +
                "It is customary to normalize the wave equation by\n" +
                "demanding that\n" +
                "\\[ \\int \\!\\!\\! \\int \\!\\!\\! \\int_{\\textbf{R}^3}\n" +
                "\\left| \\psi(\\mathbf{r},0) \\right|^2\\,dx\\,dy\\,dz = 1.\\]\n" +
                "A simple calculation using the Schr\\\"{o}dinger wave\n" +
                "equation shows that\n" +
                "\\[ \\frac{d}{dt} \\int \\!\\!\\! \\int \\!\\!\\! \\int_{\\textbf{R}^3}\n" +
                "\\left| \\psi(\\mathbf{r},t) \\right|^2\\,dx\\,dy\\,dz = 0,\\]\n" +
                "and hence\n" +
                "\\[ \\int \\!\\!\\! \\int \\!\\!\\! \\int_{\\textbf{R}^3}\n" +
                "\\left| \\psi(\\mathbf{r},t) \\right|^2\\,dx\\,dy\\,dz = 1\\]\n" +
                "for all times~$t$. If we normalize the wave function in this\n" +
                "way then, for any (measurable) subset~$V$ of $\\textbf{R}^3$\n" +
                "and time~$t$,\n" +
                "\\[ \\int \\!\\!\\! \\int \\!\\!\\! \\int_V\n" +
                "\\left| \\psi(\\mathbf{r},t) \\right|^2\\,dx\\,dy\\,dz\\]\n" +
                "represents the probability that the particle is to be found\n" +
                "within the region~$V$ at time~$t$.";

        HtmlTextView htmlTextView = (HtmlTextView) findViewById(R.id.html_text);
        htmlTextView.setImageHtml(html, new ImageClickListener() {
            @Override
            public void onClick(View widget, String src, List<String> srcs) {
                Log.i("ImageClickSpan", "src = " + src + " \nsrcs=" + srcs);
            }
        });

//        LaTexTextView htmlTextView = (LaTexTextView) findViewById(R.id.html_text);
//        htmlTextView.setLinketext(latex + html, new ImageClickListener() {
//
//            @Override
//            public void onClick(View widget, String src, List<String> srcs) {
//                Log.i("ImageClickSpan", "src = " + src + " \nsrcs=" + srcs);
//            }
//        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
